package adv328;

import adv327.Sex;
import adv327.Student;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest {
    public static void main(String[] args) {
        Map<String,String> m=new HashMap<>();
        m.put("点头","yes");
        m.put("来","come");
        m.put("去","go");
        m.put("老虎","tiger");
        m.put("猫","cat");
        m.put("猫","dog");
        System.out.println(m.size());
        System.out.println(m);
        String laohu = m.get("老虎");
        System.out.println(">"+laohu);
        String mao = m.remove("猫");
        System.out.println(mao);
        System.out.println("删除后："+m);
        System.out.println(">>>>>>>>>>>>迭代>>>>>>>>>>>>>>");
        Iterator<String> ir = m.keySet().iterator();//所有键的Set集合的迭代器
        while (ir.hasNext()){
            String key=ir.next();//获得键
            String value=m.get(key);//获得值
            System.out.println(key+"="+value);
        }
        System.out.println(">>>>>>>>>>>>Map的迭代器>>>>>>>>>>>>>>");
        //把每一组键值对放入Set
        Set<Map.Entry<String, String>> entrySet = m.entrySet();
        Iterator<Map.Entry<String, String>> ir2 = entrySet.iterator();
        while (ir2.hasNext()){
            Map.Entry<String, String> next = ir2.next();
            System.out.println(next.getKey()+"...."+next.getValue());
        }
        System.out.println(">>>>>>>>>>>>Map的增强for>>>>>>>>>>>>>>");
        for(Map.Entry<String, String> v:entrySet){
            System.out.println(v.getKey()+"=="+v.getValue());
        }
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>");
        Map<Student,String> m2=new HashMap<>();
        m2.put(new Student("王智睿", 18, Sex.男),"最帅");
        m2.put(new Student("胡汪洋", 27, Sex.男),"最瘦");
        m2.put(new Student("镍锰开", 25, Sex.男),"最高");
        m2.put(new Student("赵俊杰", 17, Sex.男),"最xiao");
        m2.put(new Student("赵俊杰", 20, Sex.妖),"最young");

        System.out.println(m2);
    }
}
